<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <link href="res/all.css" rel="stylesheet"/>
    <style>
        #editor {
            width: 800px;
            height: 720px;
            border: 5px solid rgb(218, 218, 218);
        }
    </style>
</head>
<body>
<button onclick="load17567();">加载33228行的脚本</button>
<button onclick="load1();">加载压缩后的脚本</button>
<button onclick="beautify()">beautify</button>
<div id="editor"></div>
<script src="lib/utils/Utils.js"></script>
<script src="lib/utils/DOMUtils.js"></script>
<script src="lib/utils/Eventable.js"></script>
<script src="lib/utils/Renderable.js"></script>
<script src="lib/text/ChunkedText.js"></script>
<script src="lib/text/Buffer.js"></script>
<script src="lib/text/LineTracker2.js"></script>
<script src="lib/text/TextModel2.js"></script>
<script src="lib/text/FontMeasurer.js"></script>
<script src="lib/text/RunTable.js"></script>
<script src="lib/text/TextLayout2.js"></script>
<script src="lib/Tokenizer.js"></script>
<script src="lib/modes/Stream.js"></script>
<script src="lib/modes/javascript/javascript.js"></script>
<script src="lib/text/TextStyler2.js"></script>
<script src="lib/text/Scroller.js"></script>
<script src="lib/text/Mover.js"></script>
<script src="lib/text/Selection.js"></script>
<script src="lib/text/Caret.js"></script>
<script src="lib/text/TextInput.js"></script>
<script src="lib/text/KeyBindings.js"></script>
<script src="lib/text/Commands.js"></script>
<script src="lib/text/UndoManager.js"></script>
<script src="lib/text/TextView.js"></script>
<script src="lib/Scanner.js"></script>
<script src="lib/modes/javascript/JavascriptScanner.js"></script>
<script src="lib/js-beautify/beautify.js"></script>
<script>
    var textView = new TextView();
    textView.setText('chrome下试试拖放一个压缩成一行的超大js文件看看!');
    textView.render(document.getElementById('editor'));
    // chrome 拖放文件
    document.getElementById('editor').ondragover = function (){
        return false;
    };
    document.getElementById('editor').ondrop = function (evt){
        var file;
        try {
            file = evt.dataTransfer.files[0];
        } catch(err) {
            return DOMUtils.preventDefault(evt);
        }
        var self = this;
        if (window.FileReader) {
            var reader = new FileReader();
            reader.onload = function() {
//                alert(2);
                textView.setText(reader.result);
            };
//            alert(1);
            reader.readAsText(file);
//            alert(3);
        }
        return false;
    };
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function (){
        if (xhr.readyState == 4) {
            textView.setText(xhr.responseText);
//            alert('加载结束!');
        }
    };
    function load1(){
        xhr.abort();
        xhr.open('GET', 'tangram1.js');
        xhr.send(null);
    }
    function load17567(){
        xhr.abort();
        xhr.open('GET', 'tangram.js');
        xhr.send(null);
    }
    function beautify(){
        setTimeout(function (){
            var text = textView.getText();
            var t = new Date();
            textView.setText(
                js_beautify(text)
            );
            console.log(new Date() - t);
        });
    }
</script>
</body>
</html>
